//
// Created by LiuYou on 2021/8/1.
//

#include <vector>
#include <ostream>
#include "Widget.hpp"


class Widgets::Widget::Impl {
public:
    friend std::ostream& operator<<(std::ostream& os, const Impl& rhs) {
//        os << "name: " << rhs.name << " data: " << rhs.data;
        os << "name: " << rhs.name << " data: ";
        return os;
    }

public:
//    const std::string& getName() const {
//        return name;
//    }
//
//    const std::vector<double>& getData() const {
//        return data;
//    }

public:
    Impl() = default;

    Impl(const std::string& name, const std::vector<double>& data) : name( name ), data( data ) {}

public:
    std::string name;
    std::vector<double> data;

};

Widgets::Widget::Widget() : pImpl( std::make_unique<Impl>()) {}

Widgets::Widget::Widget(const Widgets::Widget& rhs) : pImpl( std::make_unique<Impl>( *rhs.pImpl )) {}

Widgets::Widget& Widgets::Widget::operator=(const Widgets::Widget& rhs) {
    *pImpl = *rhs.pImpl;
    return *this;
}

Widgets::Widget::Widget(Widgets::Widget&& rhs) noexcept = default;

Widgets::Widget& Widgets::Widget::operator=(Widgets::Widget&& rhs) noexcept = default;

Widgets::Widget::~Widget() = default;

std::ostream& Widgets::operator<<(std::ostream& os, const Widgets::Widget& widget) {
    os << "pImpl: " << *widget.pImpl;
    return os;
}

const std::string& Widgets::Widget::getName() const {
    return pImpl->name;
}

const std::vector<double>& Widgets::Widget::getData() const {
    return pImpl->data;
}

Widgets::Widget::Widget(const std::string& name, const std::vector<double>& data) :
        pImpl( std::make_unique<Impl>( name, data )) {}



